﻿
$(function () {
    //页面初始化的工作
    initButtons();
    initMask();
});

$(document).ajaxError(function (event, request, settings) {
    hideMask();    
    var dlg = new Dialog();
    dlg.Type = "message";
    dlg.ID = "errorMessage";
    dlg.Title = "服务器错误-" + request.status;
    dlg.MessageText = "访问服务器发生错误,请求已终止！<br><a id='ajaxError' title='点击查看详情' href='#' >(错误详情)</a>";
    dlg.initDialog();
    initButtons();
    dlg.show();
    $("#ajaxError").one("click", function () {
        winopen = window.open('', '', '');
        winopen.document.write(request.responseText);
    });
});

//==================================华丽的分割线=======================================
//蒙板
function initMask() {
    if ($("#maskLayer").length == 0) {
        var vMask = $("<div id='maskLayer'/>").addClass("mask").css("display", "none");
        $("body").append(vMask);
    }
}

function showMask(layerIndex) {
    var vIndex = 999;
    if (!isNaN(layerIndex)) {
        vIndex = layerIndex;
    }

    var vheight = document.documentElement.clientHeight;
    var vTemp = $(document).height();
    var vBakHeight = (vTemp > vheight) ? vTemp : vheight;
    $("#maskLayer").css("display", "block").css("z-index", vIndex).height(vBakHeight);
    var vBodyOverFlow = $("body").css("overflow");
    $("body").attr("cssbak", vBodyOverFlow);
    $("body").css("overflow", "hidden");
}

function hideMask() {
    $("#maskLayer").css("display", "none");
    $("body").css("overflow", $("body").attr("cssbak"));
}

//==================================华丽的分割线=======================================
//获取事件
function getEvent() {
    if (document.all) return window.event;
    func = getEvent.caller;
    while (func != null) {
        var arg0 = func.arguments[0];
        if (arg0) {
            if ((arg0.constructor == Event || arg0.constructor == MouseEvent)
             || (typeof (arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) {
                return arg0;
            }
        }
        func = func.caller;
    }
    return null;
}
//清除所有页面存储
function clearAllPageSessionStorage() {
    if (window.sessionStorage) {
        window.sessionStorage.clear();
    }
}
//设置
function setPageSessionStorage(key, value) {
    if (window.sessionStorage) {
        window.sessionStorage[key] = value;
    } else {
        $(document).data(key, value);
    }
}
//获取
function getPageSessionStorage(key) {
    if (window.sessionStorage) {
        return window.sessionStorage[key];
    } else {
        return $(document).data(key); ;
    }
}

function removePageSessionStorageByKey(key) {
    if (window.sessionStorage) {
        window.sessionStorage.removeItem(key);
    }
}

function QueryString(QueryName) {
    ///	<summary>
    ///	通用方法-获取网页地址中的参数
    ///	</summary>
    ///	<param name="QueryName" type="String">参数名</param>
    ///	<returns type="String"></returns>
    //构造参数对象并初始化
    var name, value = '', i;
    var str = location.href.toString(); //获得浏览器地址栏URL串
    str = str.replace("#", "&");
    var num = str.indexOf("?");
    str = str.substr(num + 1); //截取“?”后面的参数串
    var arrtmp = str.split("&"); //将各参数分离形成参数数组
    for (i = 0; i < arrtmp.length; i++) {
        num = arrtmp[i].indexOf("=");
        if (num > 0) {
            name = arrtmp[i].substring(0, num); //取得参数名称
            value = arrtmp[i].substr(num + 1); //取得参数值
            if (name.toUpperCase() == QueryName.toUpperCase()) {
                return decodeURI(value).replace("#", "");
            }
        }
    }
    return "";
}